/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import bean.Pemesanan;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author Rifki
 */
public class TandaTerima extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            Pemesanan pesan = new Pemesanan();
            Connection connection = null;
            OracleDataSource ds;
            try {
            ds = new OracleDataSource();
            ds.setURL("jdbc:oracle:thin:@172.23.9.185:1521:orcl");
            ds.setPassword("mhs115314034");
            ds.setUser("mhs115314034");
            //             ds.setURL("jdbc:oracle:thin:@localhost:1521:xe");
            //            ds.setPassword("hr");
            //            ds.setUser("hr");
            connection = ds.getConnection();
            Statement sta = connection.createStatement();
            ResultSet rs = sta.executeQuery("select * from pemesananbarang");
            while (rs.next()) {
                sta.executeQuery("insert into penerimaanbarang values ('" + rs.getString("KODEPEMESANAN") + "'," + rs.getString("JUMLAHBARANG") + ",'" + rs.getString("IDBARANG") + "','" + rs.getString("USERNAME") + "')");
            }
            System.out.println("data berhasil diinputkan");
            } catch (SQLException ex) {
            Logger.getLogger(TandaTerima.class.getName()).log(Level.SEVERE, null, ex);
        }

            out.println("<html>");
            out.println("<head>" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" + "<title>Login</title></head>");
            out.println("<body bgcolor='blue'>" + "<table border='0' align='center'>" + "<th colspan='2'rowspan='1' width='1%' bgcolor='#red' ><h1> <font color='white'" + "<h1 align='center' style='color:#00CCFF'> Rekayasa Perangkat Lunak Berorientasi Proses </h1>" + "<h2 align='center' style='color:#00CCFF'> Sistem Informasi Gudang Alfamart </h2>" + "<h3 align='center' style='color:#00CCFF'> Kelompok ESCAMPUR </h3>" + "</font>" + " </table>");
            out.println("<form action=\"form_utama_gudang.jsp\">" + "<table align=\"center\" border=\"0\">");
            out.println("<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"kembali\" value=\"kembali ke form utama\" width=\"250\"/></td>" + "</tr></table>" + "</form>");
            out.println("</body>");
            out.println("</html>");


    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
